<template>
  <div class="table-wrap">
    <div class="search_header">
      <div></div>
      <div class="search_header_right">
        <el-select
          placeholder="项目分类"
          v-model="parameter.projectType"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectTypeOptions"
            :key="item.dictValue"
            :label="item.dictText"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="四大结构调整"
          v-model="parameter.projectSdjg"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectStructOptions"
            :key="item.dictValue"
            :label="item.dictText"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="细分类型"
          v-model="parameter.xflx"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectDivisionOptions"
            :key="item.dictValue"
            :label="item.dictText"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="项目状态"
          v-model="parameter.projectStatus"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectStatusOptions"
            :key="item.dictValue"
            :label="item.dictText"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
        <!-- <el-select
          placeholder="审核状态"
          v-model="parameter.bpmStatus"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectCheckOptions"
            :key="item.dictValue"
            :label="item.dictText"
            :value="item.dictValue"
          >
          </el-option>
        </el-select> -->
        <el-input
          placeholder="  请输入项目名称、业主单位"
          v-model="parameter.keyword"
          clearable
          @keydown.enter.native="search"
        >
          <span
            @click="search"
            slot="suffix"
            style="display: inline-block"
          >
            <Icon
              title="搜索"
              name="sousuo"
              color="#A7ADB5"
              font-size="20"
            />
          </span>
        </el-input>
      </div>
    </div>
    <el-table
      :data="projectList"
      :header-cell-style="{
        background: '#F2F6FB ',
        color: ' #6B767D'
      }"
      :row-class-name="tableRowClassName"
    >
      <el-table-column
        label="序号"
        align="center"
        show-overflow-tooltip
        width="80"
      >
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="项目编号"
        prop="projectNo"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目分类"
        prop="projectTypeText"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目名称"
        prop="projectName"
        show-overflow-tooltip
      />
      <el-table-column
        label="四大结构调整"
        prop="projectSdjgText"
        show-overflow-tooltip
      />
      <el-table-column
        label="细分类型"
        prop="xflxText"
        show-overflow-tooltip
      />
      <el-table-column
        label="建设规模"
        prop="jsgm"
        show-overflow-tooltip
        width="150"
      />
      <el-table-column
        label="建设周期"
        prop="jszqText"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目状态"
        prop="projectStatusText"
        show-overflow-tooltip
      />
      <el-table-column
        label="操作"
        show-overflow-tooltip
        min-width="40"
      >
        <template slot-scope="scope">
          <el-button
            @click="viewProject(scope.row)"
            type="text"
            style="color: #00baff; font-weight: 400"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="table-pagination" v-if="total">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="parameter.pageSize"
        @current-change="pageChange"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  queryProjectList,
  deleteProjectInfo
} from '@/api/projectMessage'
import { queryOptions } from '@/api/dict'
import Icon from '@/components/icon'
import { create } from 'sortablejs'
import { isAdmin, isEnterprise } from '@/utils/permission'

export default {
  name: 'index',
  components: {
    Icon
  },
  data() {
    return {
      projectList: [],
      total: '',
      parameter: {
        projectType: '',
        projectSdjg: '',
        xflx: '',
        projectStatus: '',
        bpmStatus: '',
        keyword: '',
        pageIndex: 1,
        pageSize: 10
      },
      roleOptions: [],
      projectTypeOptions: [], // 项目分类
      projectStructOptions: [], // 四大结构调整
      projectDivisionOptions: [], // 细分类型
      projectCheckOptions: [], // 审核状态
      projectStatusOptions: [] // 项目状态
    }
  },
  computed: {
    isAdmin() {
      return isAdmin()
    },
    isEnterprise() {
      return isEnterprise()
    }
  },
  mounted() {
    this.getAllOptions()
    this.getList()
  },
  methods: {
    // 所有选项
    getAllOptions() {
      queryOptions(
        'projectType,projectSdjg,xflx,projectStatus,bpmStatus'
      ).then((res) => {
        if (res.success) {
          // 项目分类
          this.projectTypeOptions = res.data.filter(
            (i) => i.dictCode === 'projectType'
          )[0].resourceDictItems

          // 四大结构调整
          this.projectStructOptions = res.data.filter(
            (i) => i.dictCode === 'projectSdjg'
          )[0].resourceDictItems

          // 细分类型
          this.projectDivisionOptions = res.data.filter(
            (i) => i.dictCode === 'xflx'
          )[0].resourceDictItems

          // 项目状态
          this.projectStatusOptions = res.data.filter(
            (i) => i.dictCode === 'projectStatus'
          )[0].resourceDictItems

          // 审核状态
          this.projectCheckOptions = res.data.filter(
            (i) => i.dictCode === 'bpmStatus'
          )[0].resourceDictItems
        }
      })
    },

    search() {
      this.parameter.pageIndex = 1
      this.getList()
    },

    pageChange(page) {
      this.parameter.pageIndex = page
      this.getList()
    },

    // 获取用户列表
    getList() {
      queryProjectList(this.parameter).then((res) => {
        if (res.success) {
          this.total = res.data.count
          this.projectList = res.data.list.map((item) => {
            return {
              ...item,
              // projectTypeText:
              //   this.projectTypeOptions.filter(
              //     (i) => i.value === item.projectType
              //   )[0]?.label,
              // projectSdjgText:
              //   this.projectStructOptions.filter(
              //     (i) => i.value === item.projectSdjg
              //   )[0]?.label,
              // xflxText: this.projectDivisionOptions.filter(
              //   (i) => i.value === item.xflx
              // )[0]?.label,
              // projectStatusText:
              //   this.projectStatusOptions.filter(
              //     (i) => i.value === item.projectStatus
              //   )[0]?.label,
              // bpmStatusText:
              //   this.projectCheckOptions.filter(
              //     (i) => i.value === item.bpmStatus
              //   )[0]?.label
              jszqText: item.jszq
                ? `${JSON.parse(item.jszq)[0]}  -  ${
                    JSON.parse(item.jszq)[1]
                  }`
                : ''
            }
          })
        }
      })
    },

    // 表格高亮
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'light'
      } else {
        return ''
      }
    },

    // 刷新列表
    refresh() {
      this.parameter.pageIndex = 1
      this.parameter.projectType = ''
      this.parameter.projectSdjg = ''
      this.parameter.xflx = ''
      this.parameter.projectStatus = ''
      this.parameter.bpmStatus = ''
      this.parameter.keyword = ''
      this.getList()
    },

    // 项目查看
    viewProject(row) {
      this.$router.push({
        path: '/wisdomConstruction/projectGrowthTree/detail',
        query: {
          pkid: row.pkid,
          isView: true,
          isCheck: false,
          title: '查看'
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
@import '~@/assets/css/table.scss';
</style>
